#定义集合
my_set = {1,2,3,3,4,5,6,7,8,9} #集合不允许重复
my_set_empty = set()
print(f"原{my_set}{type(my_set)}  新{my_set_empty}{type(my_set_empty)}")

#添加新元素
my_set.add(11)
print(my_set)

#移除元素
my_set.remove(11)
print(my_set)

#随机取出一个元素
my_set = {1,2,3,3,4,5,6,7,8,9}
element = my_set.pop()
print(f"取出的元素为{element},取出后集合为{my_set}")

#清空集合
my_set.clear()
print(my_set)

#取两个集合的差集
set1 = {1,2,4}
set2 = {1,3,4}
sett = set1.difference(set2)
print(sett)

#删除2个集合的差集
set1.difference_update(set2)
print(set1)
print(set2)

#两个集合合并
set1 = {1,2,4}
set2 = {1,3,4}
set3 = set1.union(set2)
print(set3)

#统计集合元素数量 len（）
set1 = {1,2,3,4,5,6,7,8,9}
length = len(set1)
print(length)

#集合的遍历
set1 = {1,2,3,4,5,6,7,8,9}
for item in set1:
    print(item)